package com.meirengu.channel.service.impl;

import com.meirengu.channel.service.HCService;
import com.meirengu.webview.service.KwThirdbackService;
import com.meirengu.webview.utils.ConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 恒昌利通接口
 *
 * @author Mao
 * @create 2017-12-15 12:11
 */
@Service
public class HCServiceImpl implements HCService {

    Logger logger = LoggerFactory.getLogger(HCServiceImpl.class);
    @Autowired
    KwThirdbackService kwThirdbackService;

    /**
     * @param
     * @return
     */

    public Integer applyLoan(String name, String mobile, String city, String car,
                             int age, String job, String house, String baodanIs,
                             String sex, int money, String shebao, String gongjijin,
                             String isbankpay, String ip, String creditCard,
                             String meiti, String time) throws Exception {

        String code = ConfigUtil.getConfig("hc.code");
        String userName = ConfigUtil.getConfig("hc.username");
        String password = ConfigUtil.getConfig("hc.password");
        String key = ConfigUtil.getConfig("hc.password");

//        Map<String, String> params = new HashMap<>();
//        params.put("name", name);
//        params.put("mobile", mobile);
//        params.put("city", city);
//        params.put("car", car);
//        params.put("age", age+"");
//        params.put("job", job);
//        params.put("house", house);
//        params.put("baodan_is", baodanIs);
//        params.put("sex", sex);
//        params.put("money", money+"");
//        params.put("source", source);
//        params.put("shebao", shebao);
//        params.put("gongjijin", gongjijin);
//        params.put("isbankpay", isbankpay);
//        params.put("ip", ip);
//        params.put("credit_card", creditCard);
//        params.put("meiti", meiti);
//        params.put("time", time.substring(0,10));
//
//
//
//        //接口调用信息表
//        KwThirdback thirdback = new KwThirdback();
//        thirdback.setInterfaceCode("zhudai");
//        thirdback.setInterfaceName("助贷网");
//        thirdback.setMobile(mobile);
//        thirdback.setSendUrl(url.toString());
//        thirdback.setParams(params.toString());
//
//        HttpUtil.HttpResult hr = null;
//        try {
//            hr = HttpUtil.doPostForm(url, params);
//            int code = hr.getStatusCode();
//            if(code == 200){
//                thirdback.setBackUrl(hr.toString());
//                thirdback.setHttpCode(200);
//                thirdback.setHttpContent(hr.toString());
//
//                logger.info("==ZhuDaiServiceImpl.applyLoan request success. result:{}", hr.toString());
//                String content = hr.getContent();
//                Integer rCode = 0;
//                rCode = Integer.parseInt(content);
//                if(rCode.intValue()>1000000){
//                    thirdback.setCode(Constants.BUSINESS_STATUS_SUCCESS);
//                    thirdback.setMessage("成功");
//                    logger.info("==ZhuDaiServiceImpl.applyLoan business success");
//                }else if (rCode.intValue()==3){
//                    thirdback.setCode(Constants.BUSINESS_STATUS_REPEAT);
//                    thirdback.setMessage("rCode: "+rCode);
//                    logger.warn("==ZhuDaiServiceImpl.applyLoan business fail");
//                }else {
//                    thirdback.setCode(Constants.BUSINESS_STATUS_OTHER);
//                    thirdback.setMessage("rCode: "+rCode);
//                    logger.warn("==ZhuDaiServiceImpl.applyLoan business fail");
//                }
//            }else {
//                thirdback.setBackUrl(hr.toString());
//                thirdback.setHttpCode(code);
//                thirdback.setHttpContent(hr.toString());
//                logger.warn("==ZhuDaiServiceImpl.applyLoan request fail. code:{}, result:{}", code, hr.toString());
//            }
//        } catch (Exception e) {
//            thirdback.setHttpCode(408);
//            thirdback.setHttpContent("Exception");
//            e.printStackTrace();
        //logger.error(ExceptionUtils.getFullStackTrace(e));
//        } finally {
//            kwThirdbackService.insert(thirdback);
//        }

        return 0;
    }

}
